package cn.kgc.mybatis.day05.mapper;

import cn.kgc.mybatis.day05.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/7/9
 * @description 基于注解形式实现数据的crud操作
 */
public interface DeptMapper {

    @Results(value = {
            @Result(property = "dName", column = "dept_name"),
            @Result(property = "id", column = "id"),
            @Result(property = "local", column = "local")
    },id = "deptMap")

    @Select("select *  from dept")
    List<Dept> deptList();

    @Select("select *  from dept where id = #{id}")
    @ResultMap("deptMap")
    Dept selectOne(Integer id);

    @Insert("insert into dept (dept_name, local) values(#{deptName},#{local})")
    Integer addDept(Dept dept);

    @Update("update dept set dept_name = #{deptName} where id = #{id}")
    Integer updateDept(Dept dept);

    @Delete(" delete from dept  where id = #{id}")
    Integer deleteDept(Integer id);

}
